package org.example;

public class Test1 {
    //leetcode 209 https://leetcode.cn/problems/minimum-size-subarray-sum/description/
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length;
        int left = 0, right = 0, sum = 0;
        int ret = Integer.MAX_VALUE;
        while (right < n) {
            while (right < n && sum < target) {
                sum += nums[right++];
            }
            while (left < right && sum >= target) {
                ret = Math.min(ret,right - left);
                sum -= nums[left++];
            }
        }
        return ret == Integer.MAX_VALUE ? 0 : ret;
    }
}
